belongsTo
Purpose
Defines a "belongs to" relationship where the class specified by belongsTo
assumes ownership of the relationship. This has the effect of controlling how deletes cascade. In other words the owning side will cascade deletes when belongsTo
is specified on the inverse side.Examples
class Book {
String title
static belongsTo = [author:Author]
}
In this example the Book
class specifies that it belongs to the Author
class, hence when an Author
instance is deleted so are all the Book
instances associated with the Author
Description
Note that belongsTo
servers to abstract the nature of the cascading behaviour in Hibernate. However, if you prefer to have full control of cascading deletes you can take advantage of the ORM DSL, which allows fine grained control of cascading deletes.